<?php

/**
 * LoginModel model for Login Controller
 *
 * @author eugene
 */
class Default_Model_LoginModel extends RCMS_Core_BaseModel {

	protected $_name = 'user';

	protected $_translateLanguages = 'translate_languages';

	protected $_configTable = 'config';

	/**
	 * Select user id from db using login and password
	 *
	 * @param string $login
	 * @param string $password
	 */
	public function selectUserIdByLoginPass($login, $password) {		
		$where = sprintf("login = '%s' AND password = '%s'", $login, md5($password));
		$select = $this->getAdapter()->select()->from($this->_name)->where($where);
		$result = $this->_adapter->fetchRow($select, null, Zend_Db::FETCH_OBJ);
		return $result;
	}

	public function selectAllLanguages() {
        $select = $this->getAdapter()->select()->from($this->_translateLanguages,array('id','language'));
        $result = $this->_adapter->fetchPairs($select);
        return $result;
    }

public function updateConfigVariableByName($name,$value)
    {
        $array = array(
           'value' => $value
        );
        $where =  sprintf(" name = '%s'", $name);
        $result = $this->getAdapter()->update($this->_configTable, $array,$where);
        return $result;
    }

	public function selectTableData($currentDate,$path,$tablename) {
		if(!is_file($path."public/translationdump/".$tablename."-".$currentDate.".txt")) {
			$select = $this->getAdapter()->select()->from($tablename);
			return $this->getAdapter()->fetchAll($select);
		}
	}

public function selectConfigValue($name) {
		$select = $this->getAdapter()->select()->from($this->_configTable)->where('name = ?',$name);
		$result = $this->getAdapter()->fetchRow($select, null, Zend_Db::FETCH_OBJ);
		if($result->value) {
			return $result->value;
		}else {
			return "";
		}
	}
	
}

